package com.lxk.controller;

import com.lxk.service.ChatService;
import com.lxk.service.SystemService;
import com.lxk.vo.ChartDataModel;
import com.lxk.vo.ReminderModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * @author JohnSoybean
 * @create 2020/4/9 16:57
 * @description 后台待办消息提示
 */
@RestController
public class SystemController {

    @Autowired
    private SystemService ss;
    @Autowired
    private ChatService cs;

    /**
     * 获取提醒数量
     * @return
     */
    @GetMapping("/reminder")
    public ReminderModel getReminderInfo() {

        Integer fahuoNum = ss.getFahuoNum();
        Integer zhongjiang = ss.getZhongjiangNum();
        Integer tixianNum = ss.getTixianNum();
        Integer tuikuanNum = ss.getTuikuanNum();
        Integer yuyueNum = ss.getYuyueNum();
        Integer liangfangNum = ss.getLiangfangNum();
        Integer jiamengNum = ss.getJiamengNum();
        Integer kefuNum = cs.getUnreadCount();

        Integer totalNum = fahuoNum + zhongjiang + tixianNum + tuikuanNum + yuyueNum + liangfangNum + jiamengNum + kefuNum;
        ReminderModel model = new ReminderModel();
        model.setFahuo(fahuoNum);
        model.setZhongjiang(zhongjiang);
        model.setJiameng(jiamengNum);
        model.setTixian(tixianNum);
        model.setTotal(totalNum);
        model.setTuikuan(tuikuanNum);
        model.setYuyue(yuyueNum);
        model.setLiangfang(liangfangNum);
        model.setKefu(kefuNum);
        return model;
    }


    /**
     * 获取图表数据
     * @return
     */
    @GetMapping("/chart")
    public ChartDataModel getChartData() {
        List<Date> lastSevenDays = ss.getLastSevenDays();
        List<BigDecimal> lastSevenSales = ss.getLastSevenSales(lastSevenDays);
        List<Integer> lastSevenPopulation = ss.getLastSevenPopulation(lastSevenDays);
        List<String> dateStrings = ss.formatDate(lastSevenDays);

        String[] strings = new String[7];
        Integer[] integers = new Integer[7];
        BigDecimal[] bigDecimals = new BigDecimal[7];

        String[] dates = dateStrings.toArray(strings);
        Integer[] population = lastSevenPopulation.toArray(integers);
        BigDecimal[] sales = lastSevenSales.toArray(bigDecimals);

        ChartDataModel model = new ChartDataModel();
        model.setDates(dates);
        model.setPopulation(population);
        model.setSales(sales);
        return model;
    }


}
